import request from './index'

// 登录
export const login = (username, password) => {
  return request.post('/user/admin/login', {
    username,
    password,
  })
}

// 获取用户列表
export const getUserList = (username, nickName, email, pageNo, pageSize) => {
  return request.get('/user/list', {
    params: {
      username,
      nickName,
      email,
      pageNo,
      pageSize,
    },
  })
}

// 获取登录者的信息
export const getUserInfo = () => {
  return request.get('/user/info')
}

// 更新用户个人信息
export const updateInfo = (data) => {
  return request.post('/user/admin/update', data)
}

export const updateInfoCaptcha = (address) => {
  return request.get('/user/update/captcha', {
    params: {
      address,
    },
  })
}
// 更新用户个人密码
export const updatePassword = (data) => {
  return request.post('/user/admin/update_password', data)
}
// 发送更改密码验证码
export const updatePasswordCaptcha = (address) => {
  return request.get('/user/update_password/captcha', {
    params: {
      address,
    },
  })
}

export const getRoles = () => {
  return request.get('/user/roles')
}

export const getUserRole = (userId) => {
  return request.get(`/user/role/${userId}`)
}

export const updateUserRole = (userId, roleIds) => {
  return request.patch(`/user/${userId}/roles`, {
    roleIds, // 确保是数组
  })
}
